<html>
<head><meta charset="utf-8"><title>repr of slices/trait objs · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html">repr of slices/trait objs</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="147760319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147760319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147760319">(Nov 15 2018 at 18:00)</a>:</h4>
<p><span class="user-mention" data-user-id="125253">@Nicole Mazzuca</span> one can communicate with C without specifying the representation of slices and trait objects.</p>



<a name="147760334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147760334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147760334">(Nov 15 2018 at 18:01)</a>:</h4>
<p>I can query the slice pointer and length and pass those to C directly, or put them in a repr(C) struct.</p>



<a name="147760361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147760361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147760361">(Nov 15 2018 at 18:01)</a>:</h4>
<p>that's of no help of a &amp;[T] is embedded in a larger data structure you'd otherwise want to share with C</p>



<a name="147760422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147760422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147760422">(Nov 15 2018 at 18:02)</a>:</h4>
<p>you'd have to create a struct on the C side of things anyways, given that C does not have slices or trait objects :/</p>



<a name="147760467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147760467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147760467">(Nov 15 2018 at 18:03)</a>:</h4>
<p>ah, no, i see what you mean</p>



<a name="147760517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147760517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147760517">(Nov 15 2018 at 18:04)</a>:</h4>
<p>still, you could memcpy it into a struct that's repr(C), except for the &amp;[T] pieces, which you translate to pointer+length</p>



<a name="147760626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147760626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147760626">(Nov 15 2018 at 18:05)</a>:</h4>
<p>i mean, you would only be able to use &amp;[T]  in C FFI as long as the C code defines it in the exact same way than we do</p>



<a name="147760886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147760886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147760886">(Nov 15 2018 at 18:09)</a>:</h4>
<p>this is correct</p>



<a name="147760899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147760899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147760899">(Nov 15 2018 at 18:10)</a>:</h4>
<p>but I'd also argue it's useful to have the repr(C) guarantee for ease of FFI</p>



<a name="147760955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147760955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147760955">(Nov 15 2018 at 18:10)</a>:</h4>
<p>not necessary, but helpful</p>



<a name="147760974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147760974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147760974">(Nov 15 2018 at 18:10)</a>:</h4>
<p>(as opposed to saying that the first word is the pointer, which isn't)</p>



<a name="147766226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147766226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147766226">(Nov 15 2018 at 19:23)</a>:</h4>
<p>You should always be using cbindgen/rust-bindgen for ffi so keeping the repr right shouldn’t be a burden</p>



<a name="147768899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147768899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147768899">(Nov 15 2018 at 19:57)</a>:</h4>
<p>?</p>



<a name="147768905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147768905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147768905">(Nov 15 2018 at 19:57)</a>:</h4>
<p>I mean for C APIs written in Rust.</p>



<a name="147769048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769048">(Nov 15 2018 at 19:59)</a>:</h4>
<p>I want to be able to declare</p>
<div class="codehilite"><pre><span></span><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
<span class="k">struct</span> <span class="n">slice</span> <span class="p">{</span>
  <span class="n">T</span><span class="o">*</span> <span class="n">ptr</span><span class="p">;</span>
  <span class="kt">size_t</span> <span class="n">length</span><span class="p">;</span>
<span class="p">};</span>

<span class="k">extern</span> <span class="s">&quot;C&quot;</span> <span class="p">{</span>
  <span class="kt">void</span> <span class="n">print_int_slice</span><span class="p">(</span><span class="n">slice</span><span class="o">&lt;</span><span class="kt">int</span> <span class="k">const</span><span class="o">&gt;</span> <span class="n">x</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>


<p>and then in rust</p>
<div class="codehilite"><pre><span></span><span class="cp">#[no_mangle]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">extern</span><span class="w"> </span><span class="s">&quot;C&quot;</span><span class="w"> </span><span class="k">fn</span> <span class="nf">print_int_slice</span><span class="p">(</span><span class="n">x</span>: <span class="kp">&amp;</span><span class="p">[</span><span class="kt">i32</span><span class="p">])</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="p">...</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>or w/e</p>



<a name="147769306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769306">(Nov 15 2018 at 20:02)</a>:</h4>
<p>I think for slices and trait objects we could commit to something. (Though we shouldnt fix vtable layout.) The original statement was about fat pointers in general, there we should be careful.</p>



<a name="147769329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769329">(Nov 15 2018 at 20:03)</a>:</h4>
<p>I don't know why I'd want to be careful here.</p>



<a name="147769359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769359">(Nov 15 2018 at 20:04)</a>:</h4>
<p>didn't you propose custom DST? then we could have fat ptrs with nobody-knows-what as metadata</p>



<a name="147769420"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769420" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769420">(Nov 15 2018 at 20:04)</a>:</h4>
<p>sure</p>



<a name="147769427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769427">(Nov 15 2018 at 20:04)</a>:</h4>
<p>why's that make a difference?</p>



<a name="147769441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769441">(Nov 15 2018 at 20:05)</a>:</h4>
<p>uh, if we say all fat ptrs are two pointer sizes large, then that restricts your custom DST proposal to ptr-sized metadata?</p>



<a name="147769451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769451">(Nov 15 2018 at 20:05)</a>:</h4>
<p>I didn't say that?</p>



<a name="147769462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769462">(Nov 15 2018 at 20:05)</a>:</h4>
<p>I didnt say <em>you</em> did</p>



<a name="147769481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769481">(Nov 15 2018 at 20:05)</a>:</h4>
<p>right, but why should we be careful about committing to the thing I said</p>



<a name="147769524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769524">(Nov 15 2018 at 20:06)</a>:</h4>
<p>obviously we can't commit to two pointers, that's a non-starter</p>



<a name="147769538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769538">(Nov 15 2018 at 20:06)</a>:</h4>
<p>okay I guess I have some context here that I thought we share but don't... one sec</p>



<a name="147769571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769571">(Nov 15 2018 at 20:06)</a>:</h4>
<p><a href="https://github.com/rust-rfcs/unsafe-code-guidelines/issues/16#issuecomment-439106988" target="_blank" title="https://github.com/rust-rfcs/unsafe-code-guidelines/issues/16#issuecomment-439106988">https://github.com/rust-rfcs/unsafe-code-guidelines/issues/16#issuecomment-439106988</a></p>



<a name="147769589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769589">(Nov 15 2018 at 20:07)</a>:</h4>
<p>What you proposed sounds absolutely reasonable, that's why I said that for slices (and trait objects) we can commit to something</p>



<a name="147769603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769603">(Nov 15 2018 at 20:07)</a>:</h4>
<p>at least for layout. I will leave ABI questions to the experts.^^</p>



<a name="147769613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769613">(Nov 15 2018 at 20:07)</a>:</h4>
<p>right, but we don't need to worry about "just for slices and trait objects"</p>



<a name="147769650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769650">(Nov 15 2018 at 20:08)</a>:</h4>
<p>I would argue we should define it forall Metadata</p>



<a name="147769666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769666">(Nov 15 2018 at 20:08)</a>:</h4>
<p>I'd rather not define anything for custom DST</p>



<a name="147769669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769669">(Nov 15 2018 at 20:08)</a>:</h4>
<p>just to keep all options open</p>



<a name="147769686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769686">(Nov 15 2018 at 20:08)</a>:</h4>
<p>hmm</p>



<a name="147769693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769693">(Nov 15 2018 at 20:08)</a>:</h4>
<p>I personally disagree, but not super strongly</p>



<a name="147769708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769708">(Nov 15 2018 at 20:09)</a>:</h4>
<p>I dont care strongly either^^</p>



<a name="147769718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769718">(Nov 15 2018 at 20:09)</a>:</h4>
<p>As I already wrote on the issue I think we <em>can't</em> define layout in terms DynamicallySized because it <em>doesn't even exist yet</em></p>



<a name="147769730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769730">(Nov 15 2018 at 20:09)</a>:</h4>
<p>(I dont care strongly about basically any layout stuff, except where it interacts with validity invariants^^)</p>



<a name="147769732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769732">(Nov 15 2018 at 20:09)</a>:</h4>
<p>Unless of course you propose waiting to define anything until we have it</p>



<a name="147769754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769754">(Nov 15 2018 at 20:10)</a>:</h4>
<p>oh, if you want to say that, sure</p>



<a name="147769802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769802">(Nov 15 2018 at 20:10)</a>:</h4>
<p>I mean right when custom DSTs are implemented, this should be defined.</p>



<a name="147769815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769815">(Nov 15 2018 at 20:10)</a>:</h4>
<p>I want to be able to use custom DSTs in C APIs</p>



<a name="147769816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147769816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147769816">(Nov 15 2018 at 20:10)</a>:</h4>
<p>yeah i agree</p>



<a name="147814293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814293">(Nov 16 2018 at 12:39)</a>:</h4>
<p>eddyb is reluctant to define {ptr, len} because we actually always pass it as two values in the rust abi, even on x86 which passes structs on the stack</p>



<a name="147814353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814353">(Nov 16 2018 at 12:40)</a>:</h4>
<p>we could just... not do that... in the C calling convention</p>



<a name="147814544"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814544" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814544">(Nov 16 2018 at 12:45)</a>:</h4>
<p>alternatively we could "just" teach cbindgen that <code>extern fn hello(data: &amp;[T])</code> is <code>void hello(T* data_ptr, size_t data_len);</code></p>



<a name="147814588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814588">(Nov 16 2018 at 12:46)</a>:</h4>
<p>Which honestly seems like more idiomatic C code</p>



<a name="147814593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814593">(Nov 16 2018 at 12:46)</a>:</h4>
<p>but is also easier to mess up your usage of</p>



<a name="147814660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814660">(Nov 16 2018 at 12:48)</a>:</h4>
<p>There is also the matter of to what extent we are guaranteeing, accidentally or not, whether {*T, usize} is type-punnable with &amp;[T]</p>



<a name="147814666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814666">(Nov 16 2018 at 12:48)</a>:</h4>
<p>I don't think it's a  <em>huge</em> concern?</p>



<a name="147814753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814753">(Nov 16 2018 at 12:50)</a>:</h4>
<p>Basically I think this is the first time we're saying "hey these are the same everywhere" instead of "hey this is specifically the valid FFI bridging, but in actual Rust code don't rely on this"</p>



<a name="147814770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814770">(Nov 16 2018 at 12:51)</a>:</h4>
<p>i think that type-punability is something we should be intentionally guaranteeing, as it's more useful than just passing immediate slices across the FFI boundary -- you can already do that today with a small wrapper that disassembles the slice, but today you can't share a big repr(C) data structure with C if it contains slice pointers</p>



<a name="147814832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814832">(Nov 16 2018 at 12:52)</a>:</h4>
<p>to be clear this is not really about type punning within Rust, but that type punning becomes legal as a side effect of allowing C to manipulate slice pointers natively</p>



<a name="147814833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814833">(Nov 16 2018 at 12:52)</a>:</h4>
<p>Correct me if I'm wrong but we try to keep the Rust ABI close to the C one so native tooling will be happier, right?</p>



<a name="147814849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814849">(Nov 16 2018 at 12:52)</a>:</h4>
<p>Uh</p>



<a name="147814853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814853">(Nov 16 2018 at 12:52)</a>:</h4>
<p>I at least haven't ever heard that articulated as a goal</p>



<a name="147814867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147814867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147814867">(Nov 16 2018 at 12:53)</a>:</h4>
<p>I might have hallucinated it, I'll check on #compiler discord</p>



<a name="147815172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815172">(Nov 16 2018 at 13:01)</a>:</h4>
<p><span class="user-mention" data-user-id="125253">@Nicole Mazzuca</span> do you think DSTs that do not contain a pointer are useful ?</p>



<a name="147815242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815242">(Nov 16 2018 at 13:02)</a>:</h4>
<p>I don't understand why so many people want to specify a layout for custom DSTs right now, when nobody has agreed yet on what custom DSTs actually are</p>



<a name="147815258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815258">(Nov 16 2018 at 13:02)</a>:</h4>
<p>say I have a global array, and write a custom DST that has a pointer to this array as an associated const, and only stores a <code>u8</code> index to index into it</p>



<a name="147815341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815341">(Nov 16 2018 at 13:04)</a>:</h4>
<p>that would be a <code>&amp;T</code> that has the same size as an <code>u8</code> - if we specify that <code>&amp;T</code> is at least pointer sized, and that for custom DSTs that they are all <code>(ptr, Metadata)</code>, then these types cannot be written.</p>



<a name="147815347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815347">(Nov 16 2018 at 13:04)</a>:</h4>
<p>if there's no data pointer component, why do you want to bludgeon it into the shame of a reference to an dynamically sized value? in your example, why not just have a newtype around an u8?</p>



<a name="147815397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815397">(Nov 16 2018 at 13:05)</a>:</h4>
<p>there is a data pointer component, it is just not stored in the DST</p>



<a name="147815448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815448">(Nov 16 2018 at 13:06)</a>:</h4>
<p>out of all the features of pointers, pretty much only the ability to return such a thing from Index::index (and variants) seems relevant, everything else (e.g. different kinds of pointers like raw vs reference vs Rc vs ..., the lifetime parameter some of these have, etc.) seems irrelevant</p>



<a name="147815464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815464">(Nov 16 2018 at 13:06)</a>:</h4>
<p>i don't really know if supporting this use case is worth it, or even useful, hence why I asked</p>



<a name="147815465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815465">(Nov 16 2018 at 13:06)</a>:</h4>
<p>and even the Index::index thing seems dubious because you'd artificially constrain yourself to returning &amp;'a YourCustomThingy, when you could return &amp;'static YourCustomThingy</p>



<a name="147815474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815474">(Nov 16 2018 at 13:07)</a>:</h4>
<p>It really sounds like you want a custom <em>pointer type</em>, not a custom <em>DST</em></p>



<a name="147815539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815539">(Nov 16 2018 at 13:08)</a>:</h4>
<p>You could write a custom pointer type than then has size == 1, but if you then <code>&amp;*</code> you would get a pointer-sized reference</p>



<a name="147815566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815566">(Nov 16 2018 at 13:09)</a>:</h4>
<p>why is that a problem?</p>



<a name="147815620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815620">(Nov 16 2018 at 13:10)</a>:</h4>
<p>you want to store it somewhere, and would prefer to store a reference type with size == 1.</p>



<a name="147815714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815714">(Nov 16 2018 at 13:12)</a>:</h4>
<p>if that place where you store it is under your control, there are ways to be reasonably generic over different pointer types (e.g. for starters P: Copy+Deref). if that place is not under your control and e.g. hardcodes <code>&amp;T</code>, it could already be doing a ton of things to this pointer that cannot be generalized to things which claim to be pointers but aren't actually an address</p>



<a name="147815715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815715">(Nov 16 2018 at 13:12)</a>:</h4>
<p>report back from discord: I had misunderstood the ABI concerns. eddyb's concerns seem to all revolve around wanting to better understand the custom DST plan to avoid any special-casing of the implementation</p>



<a name="147815726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815726">(Nov 16 2018 at 13:12)</a>:</h4>
<p>I really don't understand why custom DSTs have to be constrained to have a pointer and meta-data members internally, in any particular order</p>



<a name="147815742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815742">(Nov 16 2018 at 13:13)</a>:</h4>
<p>why do they even need a metadata: () member at all, if its just (), can't it be omitted in the type ?</p>



<a name="147815809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815809">(Nov 16 2018 at 13:14)</a>:</h4>
<p>and same for the pointer, given that we don't even have a merged RFC for custom DSTs, why do we have to specify right now that custom DSTs need to always have a pointer, and that it has to be the first member</p>



<a name="147815829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815829">(Nov 16 2018 at 13:15)</a>:</h4>
<p>even if we were to never support DSTs without a memory address, why a pointer and not an <code>usize</code></p>



<a name="147815840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815840">(Nov 16 2018 at 13:15)</a>:</h4>
<p>or a <code>NonNull&lt;*()&gt;</code></p>



<a name="147815894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815894">(Nov 16 2018 at 13:16)</a>:</h4>
<p>ok some terminology for starters: if it doesn't have a thin data pointer component and some other components that help interpret that data pointer, it's not a generalization of the concept of DSTs, it's a generalization of the concept of pointers period</p>



<a name="147815900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815900">(Nov 16 2018 at 13:16)</a>:</h4>
<p>now your question might be, why generalize DSTs specifically and not pointers in general</p>



<a name="147815910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815910">(Nov 16 2018 at 13:17)</a>:</h4>
<p>and one reason is, there's a ton of things that can be done generically over all DSTs but not necessarily over arbitrary things that are in some shape or form "like pointers". for example, <code>ThinBox&lt;T: ?Sized&gt;</code></p>



<a name="147815931"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815931" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815931">(Nov 16 2018 at 13:17)</a>:</h4>
<blockquote>
<p>why do they even need a metadata: () member at all, if its just (), can't it be omitted in the type ?</p>
</blockquote>
<p>this is just so we can talk about <em>all</em> pointers without special casing for pointers to sized types</p>



<a name="147815985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147815985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147815985">(Nov 16 2018 at 13:18)</a>:</h4>
<blockquote>
<p>even if we were to never support DSTs without a memory address, why a pointer and not an <code>usize</code></p>
</blockquote>
<p>irrelevant but a raw pointer is slightly more natural since most of the things you'd do with it are pointer things not address things</p>



<a name="147816073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816073">(Nov 16 2018 at 13:20)</a>:</h4>
<p>("irrelevant" because raw pointers and usizes are equivalent for layout and ABI so it's just a matter of where you cast, if at all)</p>



<a name="147816082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816082">(Nov 16 2018 at 13:20)</a>:</h4>
<p>if I can write my own DSTs, I can provide APIs that expose them and completely hide where they come from</p>



<a name="147816111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816111">(Nov 16 2018 at 13:21)</a>:</h4>
<p>what wouuld <code>ThinBox&lt;YourU8IndexIntoGlobalArray&gt;</code> or <code>Rc&lt;YourU8IndexIntoGlobalArray&gt;</code> even mean?</p>



<a name="147816187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816187">(Nov 16 2018 at 13:22)</a>:</h4>
<p>that's the question</p>



<a name="147816217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816217">(Nov 16 2018 at 13:23)</a>:</h4>
<p>for custom DSTs as defined in the various DSTs it's completely clear what Rc, ThinBox, etc. mean. for your example i don't even think it can be made to make sense</p>



<a name="147816229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816229">(Nov 16 2018 at 13:23)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> those imply some sort of ownership, but I don't have to expose a way to create T, just expose &amp;T</p>



<a name="147816279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816279">(Nov 16 2018 at 13:24)</a>:</h4>
<p>that's why I say you want a new kind of pointer, instead of a new kind of type that can be referenced by any pointer</p>



<a name="147816288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816288">(Nov 16 2018 at 13:24)</a>:</h4>
<p>ah I see</p>



<a name="147816303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816303">(Nov 16 2018 at 13:25)</a>:</h4>
<p>I thought custom DSTs would also allow implementing <code>&amp;T</code></p>



<a name="147816316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816316">(Nov 16 2018 at 13:25)</a>:</h4>
<p>or that it would be an aim of that at some point</p>



<a name="147816325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816325">(Nov 16 2018 at 13:25)</a>:</h4>
<p>first I heard of that</p>



<a name="147816326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816326">(Nov 16 2018 at 13:25)</a>:</h4>
<p>no, just as the existing DSTs are str and [T] and <code>dyn Bounds</code> and so on, not &amp;str, &amp;[T], <code>&amp;dyn Bounds</code></p>



<a name="147816431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816431">(Nov 16 2018 at 13:27)</a>:</h4>
<p>so yeah, i'd like a way to create custom pointers then</p>



<a name="147816536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816536">(Nov 16 2018 at 13:29)</a>:</h4>
<p>thinking about DSTs, I guess it also wouldn't be possible to have DSTs where the meta-data is encoded in the pointer then ?</p>



<a name="147816605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816605">(Nov 16 2018 at 13:30)</a>:</h4>
<p>as in, the metadata has to be a distinct field of the DST</p>



<a name="147816650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816650">(Nov 16 2018 at 13:31)</a>:</h4>
<p>this seems very off-topic</p>



<a name="147816666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816666">(Nov 16 2018 at 13:31)</a>:</h4>
<p>yeah best take this question to a specific proposal about custom DSTs</p>



<a name="147816678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr%20of%20slices/trait%20objs/near/147816678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/repr.20of.20slices.2Ftrait.20objs.html#147816678">(Nov 16 2018 at 13:31)</a>:</h4>
<p>so specifying custom DSTs as (*T, Metadata) does not prevent this?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>